#ifndef __EKOS_KERNEL_VMEM_H__
#define __EKOS_KERNEL_VMEM_H__

extern struct segdesc_t gdt[GDT_COUNT];
int vmem_init(void);
int vmem_init_ap(physaddr_t cr3);
int vmem_post_fix(void);

/* control the temp page for current kstack */
void        *get_tpage();
void        *set_tpage(physaddr_t addr);

/* simple function for getting and setting the current vpt */
void         set_vpt(void *vaddr, uint32_t pte);
ptab_entry_t get_vpt(void *vaddr);

/* These macros define a simple method for using tpage space,
   all the data should not exceed the 4K page boundary */
#define BEGIN_TPAGE(ADDR, VAR)					  \
	 { uint32_t __old = get_vpt((void *)get_tpage());	\
	   VAR = set_tpage(ADDR)

#define EXIT_TPAGE set_vpt(get_tpage(), __old)
#define END_TPAGE set_vpt(get_tpage(), __old); }

/* a universe function for vpt management */
#define    FA_COW 1
#define	   FA_AWA 2
#define    fix_addr(args ...) __fix_addr(0, args)
int        __fix_addr(int verbose, void *addr, ptab_entry_t *create, ...);

physaddr_t vmem_vpt_new(void);

#endif
